//
//  BasicRequest.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/26.
//  
  

#import "BasicRequest.h"
#import "LoginRequestAccessory.h"
#import "RequestCommonParameter.h"


@implementation BasicRequest

- (instancetype)init {
    if (self = [super init]) {
        LoginRequestAccessory *loginAccessory = [LoginRequestAccessory new];
        if (!self.requestAccessories) {
            self.requestAccessories = [NSMutableArray array];
        }
        [self.requestAccessories addObject:loginAccessory];
    }
    return self;
}
- (NSString *)commonQuery {
    NSDictionary *query = [RequestCommonParameter parameter];
    NSMutableArray *arr = [NSMutableArray array];
    for (NSString *key in query.allKeys) {
        [arr addObject:[NSString stringWithFormat:@"%@=%@", key, query[key]]];
    }
    NSString *str = [arr componentsJoinedByString:@"&"];
    return [NSString stringWithFormat:@"?%@", str];
}

- (NSString *)requestEncodingUrl:(NSString *)uri {
    uri = [uri stringByAppendingString:self.commonQuery];
    NSCharacterSet *allowedCharacters = [NSCharacterSet URLQueryAllowedCharacterSet];
    return [uri stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
}
@end
